Repository navigation
Conversation
|
There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated. |
|
hey can anyone create trac ticket for this pr, thanks. |
|
I have created https://trac.cppcheck.net/ticket/15180 |
|
Thanks for creating the ticket. I've updated the title to reference #15180. |
|
I think there is some clang-tidy warning, the CI log says: |
|
Fixed, added the parentheses around |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. With the PR, checkFormatString no longer throws on these format strings: %$d, %01$d, %99999999999$d, and widths too large for an int in %s, %c and %[...] scanf conversions. The positions and widths that fit in an int give the same results as before. A position or width above INT_MAX is reported as 2147483647. The PR description says so, and the new tests expect it. Two different huge positions are also clamped to the same number, so they count as one parameter. That only matters for format strings that are already wrong. No strToInt calls are left in lib/checkio.cpp. The only earlier request was the clang-tidy parentheses warning, and it is fixed.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR should have a trac ticket and reference it in the title | @dmcppcheck | general | ✅ Fixed |
| 2 | clang-tidy readability-math-missing-parentheses in formatStringNumber | @danmar | general | ✅ Fixed |
Testing
- Built
cppcheckandtestrunnerinpr/withmake -j8. It built cleanly. ./testrunner TestIO: 38 tests, 0 failed (1 todo).- I ran
pr/cppcheck -q --enable=all t.con this file:
void f(void) {
char s[8];
printf("%$d %s\n", 1);
printf("%01$d %1$d\n", 1);
printf("%2147483648$d %2147483649$d\n", 1);
scanf("%99999999999c", s);
scanf("%.99999999999s", s);
scanf("%000000000000000000007s", s);
scanf("%0000000000000000000099999999999[a-z]", s);
printf("%1$d %2$d %3$d\n", 1, 2, 3, 4);
printf("%0$d %00$d\n", 1);
}There was no internalError, and every diagnostic was what I expected:
%$d %s: wrongPrintfScanfArgNum.%01$d %1$d: no warning, since both are position 1.- The positions above INT_MAX: one wrongPrintfScanfParameterPositionError, which names 2147483647.
- The widths too large for an int in
%c,%.…sand%[a-z]: invalidScanfFormatWidth, which shows 2147483647. - The width
7with many leading zeros: no warning, which is correct. %0$dand%00$d: "parameter positions start at 1".- I did not build
base/for comparison, because the PR description and the new tests already cover the old throwing behaviour.
Automated review of bb08439 by Claude. The pull request was built and tested locally.
CheckIOImpl::checkFormatString converts the digits collected for a field width or a POSIX parameter position with strToInt, which throws when the digits are empty (
%$d), start with a zero (%01$d, which glibc accepts) or do not fit in an int (%99999999999$d,scanf("%99999999999s", buf)with a known array), so one such format string makes CppCheck::checkFile bail out with an internalError and drop every other diagnostic for that file. Replaced the conversion with a small helper that parses the digits without throwing and clamps anything above INT_MAX, and a$with no digits in front is no longer taken as a parameter position; widths and positions that fit in an int behave exactly as before, while an oversized one is now reported through the existing invalidScanfFormatWidth and wrongPrintfScanfParameterPositionError messages, with 2147483647 shown for the clamped value. Verified with an ASan/UBSan build: the new asserts in TestIO::testScanf4 and testPosixPrintfScanfParameterPosition throw on main and pass with the fix, the full testrunner is green, and the selfcheck options report nothing for lib/checkio.cpp. I do not have Trac access, so could you create a ticket for this? I will update the title to reference it once there is a number.